//
//  CLPagerView.h
//  Charles
//
//  Created by Leo on 2019/4/25.
//  Copyright © 2019 charles. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "CLPagerViewLayout.h"

NS_ASSUME_NONNULL_BEGIN
@class CLPagerView;
@protocol CLPagerViewDataSource <NSObject>

- (NSInteger)numberOfViewsInPagerView;
- (UIView *)pagerView:(CLPagerView *)pagerView viewForIndex:(NSInteger)index prefetching:(BOOL)prefetching;

@end

@protocol CLPagerViewDelegate <NSObject>

@optional
- (void)pagerView:(CLPagerView *)pagerView willAppearView:(UIView *)view forIndex:(NSInteger)index;
- (void)pagerView:(CLPagerView *)pagerView didAppearView:(UIView *)view forIndex:(NSInteger)index;

- (void)pagerView:(CLPagerView *)pagerView willDisappearView:(UIView *)view forIndex:(NSInteger)index;
- (void)pagerView:(CLPagerView *)pagerView didDisappearView:(UIView *)view forIndex:(NSInteger)index;

- (void)pagerView:(CLPagerView *)pagerView transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex animated:(BOOL)animated;
- (void)pagerView:(CLPagerView *)pagerView transitionFromIndex:(NSInteger)fromIndex toIndex:(NSInteger)toIndex progress:(CGFloat)progress;

- (void)pagerViewDidScroll:(CLPagerView *)pagerView;
- (void)pagerViewWillBeginScrolling:(CLPagerView *)pagerView animate:(BOOL)animate;
- (void)pagerViewDidEndScrolling:(CLPagerView *)pagerView animate:(BOOL)animate;

@end

@interface CLPagerView : UIView

@property (nonatomic, weak, nullable) id<CLPagerViewDataSource>dataSource;
@property (nonatomic, weak, nullable) id<CLPagerViewDelegate> delegate;
@property (nonatomic, strong, readonly) CLPagerViewLayout<UIView *> *layout;
@property (nonatomic, strong, readonly) UIScrollView *scrollView;
@property (nonatomic, assign, readonly) NSInteger countOfPagerViews;
@property (nonatomic, assign, readonly) NSInteger curIndex;

@property (nonatomic, assign, nullable, readonly) NSArray <UIView *>*visibleViews;
@property (nonatomic, assign) UIEdgeInsets contentInset;

- (UIView *_Nullable)viewForIndex:(NSInteger)index;

- (void)registerClass:(Class)Class forViewWithReuseIdentifier:(NSString *)identifier;
- (void)registerNib:(UINib *)nib forViewWithReuseIdentifier:(NSString *)identifier;

- (UIView *)dequeueReusableViewWithIdentifier:(NSString *)identifier forIndex:(NSInteger)index;
- (void)scrollToViewAtIndex:(NSInteger)index animate:(BOOL)animate;

- (void)updateData;
- (void)reloadData;

@end

NS_ASSUME_NONNULL_END
